package com.zj.easywebview.util

import android.view.ViewGroup
import android.webkit.WebView

/**
 * @author: witness
 * created: 2021/10/8
 * desc:
 */
object WebUtils {
    fun clearWebview(mWebView: WebView?) {
        if (mWebView != null) {
            try {
                (mWebView.parent as ViewGroup).removeAllViews()
                mWebView.stopLoading()
                mWebView.clearCache(true)
                // 退出时调用此方法，移除绑定的服务，否则某些特定系统会报错
                mWebView.settings.javaScriptEnabled = false
                mWebView.clearHistory()
                mWebView.clearView()
                mWebView.removeAllViews()
                mWebView.destroy()
            } catch (ex: Throwable) {
                ex.printStackTrace()
            }
        }
    }
}